/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：BattleStart.java <br>
 * 创建时间：2013-8-5 下午5:53:03 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.battle.proc;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.SavingScreen;
import lostland.gmud.exv2.battle.BattleOverScreen;
import lostland.gmud.exv2.battle.BattleScreen;
import lostland.gmud.exv2.battle.netbattle.NetworkMode;
import lostland.gmud.exv2.data.Item;
import lostland.gmud.exv2.data.Npc;
import lostland.gmud.exv2.data.Room;

/**
 * 类名：BattleStart <br>
 * 说明：战斗开始
 *
 * @author 12548
 */
public class BattleStart extends Status {

	public static Item wp0;
	public static Item wp; //敌人武器的临时存储（战斗中被落英缤纷掉或流星飞掷掉，战斗结束后可以回收武器）
	public static String name = "You"; //玩家姓名的临时存储

	/**
	 * @param zdp 主动方
	 * @param bdp 被动方
	 */
	public BattleStart(Npc zdp, Npc bdp) {
		super(zdp, bdp);
		BattleScreen.setWFlag(zdp != Gmud.mc);
	}

	int med(int defpluslvl) {
		int b = 0;
		if (defpluslvl > 0) {
			b++;
		}
		if (defpluslvl > 2) {
			b++;
		}
		return b;
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.battle.proc.Status#execute()
	 */
	@Override
	public void execute() {
		if (Game.getInstance().data.auto_save) {
			new SavingScreen().save();
		}


		zdp.setBattleData(BattleScreen.getInstance().bd1);
		bdp.setBattleData(BattleScreen.getInstance().bd2);
		zdp.getBattleData().refresh();
		bdp.getBattleData().refresh();

		if (BattleScreen.wflag) {
			zdp = Gmud.getNpc(BattleScreen.getInstance().leftid);
			zdp.setDrug2(med(Game.getInstance().data.game_difficulty - 1)); //0 0 1 1
			zdp.setDrug1(med(Game.getInstance().data.game_difficulty)); //0 1 1 2
			zdp.refresh();

			if (zdp.haveTalent(131)) {
				zdp.setFp(bdp.getAttr(Room.ATTR_MAXFP) * 2);
				zdp.exp = bdp.getAttr(Room.ATTR_EXP) * 2;
			}
		} else {
			zdp = Gmud.mc;
			wp0 = Gmud.mc.getAttackItem();
			wp = Gmud.getNpc(BattleScreen.getInstance().enemyid).getAttackItem();
			name = Gmud.mc.name;
			if (!(BattleScreen.getInstance().networkMode == NetworkMode.HOST)) {
				Gmud.mc.name = "你";
			}


			if (Game.getInstance().wulindahui != null) {
				zdp.refresh();
			}
		}

		//npc的武器和护甲获得正比于其等级和难度的强化效果
//		bdp.getAttackItem().randomUpdate((int) (bdp.getpj() * Game.getInstance().data.game_difficulty * 0.1));
//		bdp.equipments[2].randomUpdate((int) (bdp.getpj() * Game.getInstance().data.game_difficulty * 0.1));

		bdp.delFlag(Npc.FLAG_UNFIGHTABLE);
		bdp.setDrug2(med(Game.getInstance().data.game_difficulty - 1));
		bdp.setDrug1(med(Game.getInstance().data.game_difficulty));
		bdp.refresh();

		if (bdp.haveTalent(131)) {
			bdp.setFp(zdp.getAttr(Room.ATTR_MAXFP) * 2);
			bdp.exp = zdp.getAttr(Room.ATTR_EXP) * 2;
		}


		BattleScreen.getInstance().eob = false;
		BattleOverScreen.tpflag = false;

		if (zdp.haveTalent(2053)) {
			bdp.setFp(0);
		}
		if (bdp.haveTalent(2053)) {
			zdp.setFp(0);
		}

		final boolean xg = bdp.getNewpj() < zdp.getNewpj();
		if (xg) {
			BattleScreen.getInstance().setStatus(new RoundOverStatus(bdp, zdp));
			//			Gmud.bs.push(new FreeStatus(zdp,bdp));
		} else {
			BattleScreen.getInstance().setStatus(new RoundOverStatus(zdp, bdp));
			//			Gmud.bs.push(new FreeStatus(bdp,zdp));
		}
	}
}
